<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<shiro:hasPermission name="MG_PERMISSION" />
	<div>
		<table id="gridPermission" class="easyui-datagrid" title="系统功能列表" style="width: fill; height: 650px;"
			data-options="singleSelect:true,iconCls:'icon-database',border:false,nowrap:false,rownumbers:true,url:'${patch}/system/permission/list.do'">
			<thead>
				<tr>
					<th data-options="field:'id',hidden:true">Id</th>
					<th data-options="field:'code',width:120,align:'center'">功能编码</th>
					<th data-options="field:'name',width:180,align:'center'">功能名称</th>
					<th data-options="field:'url',align:'left'">功能地址</th>
					<th data-options="field:'description',align:'center'">功能描述</th>
				</tr>
			</thead>
		</table>
	</div>
	<div id="winPermission" class="easyui-window" title="添加新功能"
		data-options="modal:true,closed:true,minimizable:false,maximizable:false,collapsible:false,iconCls:'icon-save'"
		style="width: 530px; height: 380px; padding: 5px;"></div>
	<script type="text/javascript">
		$("#gridPermission")
				.datagrid(
						{
							toolbar : [
									{
										text : '添加',
										iconCls : 'icon-add',
										handler : function() {
											$("#winPermission")
													.window(
															{
																href : "${path}/system/permission/addNew.do"
															});
											$('#winPermission').window('open')
													.panel('refresh');
										}
									},
									{
										text : "编辑",
										iconCls : "icon-edit",
										handler : function() {
											var data = $("#gridPermission")
													.datagrid("getSelected");
											if (null == data) {
												$.messager.alert("提示信息",
														"请选择你要编辑的数据。");
											} else {
												$("#winPermission")
														.window(
																{
																	href : "${path}/system/permission/edit.do?id="
																			+ data.id
																});
												$("#winPermission").window(
														"open")
														.panel("refresh");
											}
										}
									},
									{
										text : '删除',
										iconCls : 'icon-remove',
										handler : function() {
											var data = $("#gridPermission")
													.datagrid("getSelected");
											if (null == data) {
												$.messager.alert("提示信息",
														"请选择你要删除的数据。");
											} else {
												$.messager
														.confirm(
																"提示信息",
																"你确定要删除所选数据吗！？",
																function(isOk) {
																	if (isOk) {
																		$
																				.ajax({
																					url : "${path}/system/permission/remove.do?id="
																							+ data.id,
																					type : "GET",
																					dataType : "json",
																					success : function(
																							data) {
																						if (null != data.message) {
																							$.messager
																									.alert(
																											"提示信息",
																											data.message);
																						} else {
																							$.messager
																									.alert(
																											"提示信息",
																											"数据删除成功！");
																						}
																						refreshGrid();
																					}
																				});
																	}
																});
											}
										}
									} ]
						});

		$('#winPermission').window({
			onClose : function() {
				refreshGrid();
			}
		});

		function closeWindow() {
			$('#winPermission').window('close');
		}

		function refreshGrid() {
			$('#gridPermission').datagrid('reload');
		}
	</script>
</body>
</html>